package com.woniuxy.mesboot.security;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.woniuxy.mesboot.util.Result;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ：lisir
 * @date ：Created in 2023/5/30 10:59
 * @description：TODO
 */
@Component
public class JWTLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        response.setContentType("application/json;charset=UTF-8");
        String string = new ObjectMapper().writeValueAsString(Result.ok("登出成功"));
        response.getWriter().println(string);
    }
}
